package com.swpu.cbg.cnshop.adapter;

import android.content.Context;
import android.net.Uri;

import com.facebook.drawee.view.SimpleDraweeView;
import com.swpu.cbg.cnshop.R;
import com.swpu.cbg.cnshop.bean.ShoppingCart;

import java.util.List;

public class WareOrderAdapter extends BaseAdapter<ShoppingCart,BaseViewHolder> {


    public WareOrderAdapter(Context mContext, List<ShoppingCart> mDatas, int itemViewID) {
        super(mContext, mDatas, itemViewID);
    }

    public float getTotalPrice(){

        float sum=0;
        if(!isNull())
            return sum;

        for (ShoppingCart cart:
                mDatas) {

                sum += cart.getCount()*cart.getPrice();
        }

        return sum;

    }


    private boolean isNull(){

        return (mDatas !=null && mDatas.size()>0);
    }


    @Override
    void bindData(BaseViewHolder holder, int position) {
        SimpleDraweeView draweeView = (SimpleDraweeView) holder.getView(R.id.drawee_view);
     //   draweeView.setImageURI(Uri.parse("https://raw.githubusercontent.com/facebook/fresco/gh-pages/static/fresco-logo.png"));
        draweeView.setImageURI(Uri.parse(mDatas.get(position).getImgUrl()));
    }
}
